package com.lzw.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzw.bean.User;
import com.lzw.bean.Users;
import com.lzw.bean.result.UsersResult;
import com.lzw.mapper.UsersMapper;
import com.lzw.service.UsersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther: lzw
 * @date: 2021/10/9 - 10 - 09 - 14:30
 * @Description: com.lzw.service.impl
 */
@Service
@Slf4j
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersMapper usersMapper;

    @Override
    public UsersResult getUsersList(Integer pageNum, Integer pageSize, String query) {
        Page<Users> page = PageHelper.startPage(pageNum, pageSize);
        List<Users> usersList = null;
        if ("".equals(query) || query == null){
            usersList = usersMapper.getUsersList();
        }else {
            usersList = usersMapper.getUsersListByQuery(query);
        }

        List<Users> result = usersList.subList(0, usersList.size());
        log.info("返回的列表内容：~~~~~~~~~>" + result);
        int totalpage = (int)page.getTotal();
        return new UsersResult(totalpage,pageNum,result);
    }

    @Override
    public Integer updateUserStatus(Integer id, boolean mg_state) {
        return usersMapper.updateUserStatus(id,mg_state);
    }

    @Override
    public Integer addUser(User user) {
        return usersMapper.addUser(user);
    }

    @Override
    public User getUser(User user) {
        return usersMapper.getUser(user);
    }

    @Override
    public User getUser(Integer id) {
        return usersMapper.getUserById(id);
    }

    @Override
    public Integer updateUserInfo(Integer id, String email, String mobile) {
        return usersMapper.updateUserInfo(id,email,mobile);
    }

    @Override
    public Integer deleteUser(Integer id) {
        return usersMapper.deleteUser(id);
    }
}
